<div class="layui-fluid"></div>
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-card-box">
                <div class="layui-btn-group">
                    <a class="layui-btn" id="config-add" v-show="@system.setting/badd"><i class="layui-icon layui-icon-add-circle"></i> 添加</a>
                    <a class="layui-btn" id="config-del" v-show="@system.setting/bdel"><i class="layui-icon layui-icon-delete"></i> 删除</a>
                </div>
                <form class="layui-form render" style="float:right;">
                    <div class="layui-form-item">
                        <div class="layui-inline" style="width:150px;"><input type="text" name="kw" placeholder="关键词" autocomplete="off" class="layui-input" lay-affix="clear"/></div>
                        <div class="layui-inline">
                            <div class="layui-btn-group">
                                <button class="layui-btn" lay-submit lay-filter="search-config"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                                <a class="layui-btn" lay-submit lay-filter="search-config-all-group"><i class="layui-icon layui-icon-light"></i>全部</a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-card-body">
                <table id="config"></table>
            </div>
        </div>
    </div>
</div>
<!--JS部分-->
<script>
layui.use(['buildItems'],function(){
    var map_root = layui.cache.maps;
    var app_root = layui.cache.maps + 'config/';
    var table=layui.table,form=layui.form,admin=layui.admin;
    /*渲染数据*/
    table.render({
        elem: '#config',
        page: true,
        limit:{$limit},
        url: app_root+"index?do=json",
        cols: [[
            {type:'checkbox',fixed:'left'},
            {field:"id",align:'center',title:"Id", width:80 },
            {field:"created_at",align:'center',title:"创建时间", width:150},
            {field:"title",edit:'text', align:'center',title:"名称"},
            {field:"page_type_text", align:'center',title:"类型"},
            {field:"img",align:'center',title:"图片",  templet:function(d){return d.img ? '<img src="'+d.img+'">' : '';}},
            {field:"item_id",edit:'text', align:'center',title:"Id"},
            {fixed:'right',width:95,align:'center',toolbar:'<div><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a></div>',title:'操作'}
        ]]
    });
    /*顶部添加按钮*/
    $('#config-add').on('click',function(){configOpen();});/**/
    /*顶部删除按钮*/
    $('#config-del').on('click',function(){
        var checkRows = table.checkStatus('config').data;
        if(checkRows.length === 0){return layer.msg('请选择需删除的配置项');}
        var ids = checkRows.map(function(d){return d.id;});
        del(ids);
    });/**/
    /*快编监听*/
    table.on('edit(config)',function(obj){
        admin.req(app_root+"bedit?do=up",{id:obj.data.id,av:obj.value,af:obj.field},function(res){
            layer.msg(res.msg,{shade:[0.4,'#000'],time:1500},function(){
                if(res.code==1 && obj.field=='sort') table.reloadData('config');
            });
        },'post',{headersToken:true});
    });/**/
    /*是否隐私、启用状态*/
    form.on('switch(config-chang)',function(obj){
        var json = JSON.parse(decodeURIComponent($(this).data('json')));
        var av = obj.elem.checked ? 1 : 0;
        admin.req(app_root+"bedit?do=up",{id:json.id,av:av,af:obj.elem.name},function(res){
            layer.tips(res.msg,obj.othis,{time:2000});
            if(res.code === 0) obj.elem.checked = parseInt(obj.value);
        },'post',{headersToken:true});
    });/**/
    /*工具条监听*/
    table.on('tool(config)', function(obj){
        var data = obj.data;
        if(obj.event === 'edit'){
            configOpen(data);
        }else if(obj.event === 'del'){
            del(data.id);
        }
    });/**/
    /*删除*/
    function del(ids){
        layer.confirm('确定要删除所选配置项吗？',function(){
            admin.req(app_root+"bdel",{id:ids},function(res){
                layer.msg(res.msg,{shade:[0.4,'#000'],time:1500},function(){
                    if(res.code===1) table.reloadData('config');
                });
            },'post',{headersToken:true});
        });
    }/**/
//     CREATE TABLE `lcxx_page_config` (
//   `id` bigint(20) NOT NULL AUTO_INCREMENT,
//   `created_at` datetime DEFAULT NULL COMMENT '创建时间',
//   `updated_at` datetime DEFAULT NULL COMMENT '更新时间',
//   `title` varchar(50) NOT NULL DEFAULT '' COMMENT '标题',
//   `img` varchar(255) NOT NULL DEFAULT '' COMMENT '图片',
//   `page_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '类型 1 活动详情 2 展览 3作品',
//   `item_id` int(10) NOT NULL DEFAULT '0',
//   PRIMARY KEY (`id`)
// ) ENGINE=InnoDB AUTO_INCREMENT=251 DEFAULT CHARSET=utf8mb4;
    /*弹出窗*/
    function configOpen(Dt){
        admin.open({
            type: 1,
            bid: 'config_items',
            btn: ['保存', '取消'],
            area: ['1000px', '90%'],
            title: Dt ? '编辑艺术展览' : '添加艺术展览',
            success: function(l,index){
                var id = Dt ? Dt.id : '-1';
                layui.buildItems.build({
                    bid: 'config_items',
                    data: [
                        {name:"id",type:"hidden"},
                        {name:"title",title:"名称",type:"text",value:'',verify:'required',placeholder:"请输入名称",must:true},
                        {name:"img",title:"图片",type:"image",value: Dt ? Dt.img : '',placeholder:"请上传图片"   ,must:true},
                        {name:"page_type",title:"类型",type:"html",value:'',verify:'required',placeholder:"请选择类型",must:true, html:'<select name="page_type"><option value="1">活动详情</option><option value="2">展览</option><option value="3">作品</option></select>'},
                        {name:"item_id",title:"Id",type:"text",value:'',verify:'required',placeholder:"请输入Id",must:true},
                    ],
                    map: map_root + 'system.upload/',
                    gid: 3
                });
                form.val('config_items_form',Dt);
                form.on('submit(config_items)',function(data){
                    var btn = $(this);
                    if (btn.attr('stop')){return false}else{btn.attr('stop',1)}
                    admin.req(app_root + (data.field.id ? 'bedit' : 'badd'),data.field,function(res){
                        layer.msg(res.msg,{shade:[0.4,'#000'],time:1500},function(){
                            if(res.code==1){
                                layer.close(index);
                                table.reload('config');
                            }
                            btn.removeAttr('stop');
                        });
                    },'post',{headersToken:true});
                    return false;
                });
            }
        });
    }/**/
});
</script>